#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[210];
ll sum[210][210];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],a[i+n]=a[i];
    
    for(int len=2;len<=n;len++)
    {
        for(int l=1;l+len-1<=2*n;l++)
        {
            int r=l+len-1;
            
            for(int k=l;k<r;k++)
            {
                if(sum[l][r]<a[l]*a[k+1]*a[r+1]+sum[l][k]+sum[k+1][r])
                {
                    sum[l][r]=a[l]*a[k+1]*a[r+1]+sum[l][k]+sum[k+1][r];
                }
            }
        }
    }
    
    ll ans=0;
    for(int l=1;l+n-1<=2*n;l++)
    {
        int r=l+n-1;
        ans=max(ans,sum[l][r]);
    }
    cout<<ans;
    return 0;
}

 
